package com.apes.fico.finance.model.costcollect;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = StoreTasks.CONST_TABLE_NAME)
public class StoreTasks extends Model  {
    public final static String CONST_TABLE_NAME = "gl_store_tasks";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "门店经营任务", padding = 8)
    @Comment("编号")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id", nullable = false)
    @Comment("部门")
    private Dept dept;

    @JSONField(format = DateUtil.SHOW_MONTH_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull
    @Column(name = "year_month")
    @Comment("年月")
    private Date yearMonth;

    public void setYearMonth(String yearMonth) throws ParseException {
        Date parse = new SimpleDateFormat("yyyy-MM").parse(yearMonth);
        this.yearMonth=parse;
    }


    @Column(name = "business_tasks_amt", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("经营任务(元)")
    private double businessTasksAmt = 0;

    @Column(name = "gross_profit_tasks_amt", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("毛利任务(元)")
    private double grossProfitTasksAmt = 0;

    @Column(name = "business_amt", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("营业额(元)")
    private double businessAmt = 0;

    @Column(name = "gross_profit_amt", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("毛利额(元)")
    private double grossProfitsAmt = 0;

    @Column(name = "summary")
    @Comment("摘要")
    private String summary;
}
